import { plateform } from '@/utils/util';

const shareCardMixin = {
  data() {
    return {
      initialFontSize: 14
    };
  },
  methods: {
    resetZoom() {
      try {
        if (plateform.isiOS) {
          document
            .getElementsByTagName('body')[0]
            .classList.add('no-page-zoom');
        } else {
          const bodyDom = document.getElementsByTagName('body')[0];
          this.initialFontSize = parseFloat(
            window.getComputedStyle(bodyDom).fontSize
          );
          /* eslint-disable-next-line no-undef */
          // WeixinJSBridge.invoke('setFontSizeCallback', { fontSize: 0 });
        }
      } catch (err) {
        console.log(err);
      }
    },
    popupClose() {
      try {
        // iOS缩放还原到用户设置比例
        if (plateform.isiOS) {
          document
            .getElementsByTagName('body')[0]
            .classList.remove('no-page-zoom');
        } else {
          // 安卓缩放还原到用户设置比例
          const bodyDom = document.getElementsByTagName('body')[0];
          const bodyFontSize = parseFloat(
            window.getComputedStyle(bodyDom).fontSize
          );
          const rate = this.initialFontSize / bodyFontSize;
          let fontSizeRate = 0; // 标准
          const tofixedRate = rate.toFixed(2);
          switch (tofixedRate) {
            case '0.75': // 较小
              fontSizeRate = 1;
              break;
            case '1.50': // 大
              fontSizeRate = 3;
              break;
            case '2.00': // 较大
              fontSizeRate = 4;
              break;
            default:
              break;
          }
          if (!fontSizeRate) return;
          /* eslint-disable-next-line no-undef */
          // WeixinJSBridge.invoke('setFontSizeCallback', {
          //   fontSize: fontSizeRate
          // });
        }
      } catch (err) {
        console.log(err);
      } finally {
        this.$emit('showToast');
      }
    }
  }
};

export default shareCardMixin;
